home *** CD-ROM | disk | FTP | other *** search
/ Stolen Data 8 / Stolen Data 8.adf / SOURCE / MFMLOADER.S
Text File  |  1989-08-16  |  6KB  |  301 lines

  1. **MFM TRACK LOADER (V1.6)
  2. **EARLY VERSIONS CODED BY NEGATIVE ACTION OF KILLERS !
  3. **NOW ++OMICRON++ OF WIZZCAT !
  4. ** ASSEMBLED USING DEVPAC2.14
  5.  
  6. **PUT ONTO BOOTBLOCK USING UTIL. SUCH AS BOOTWRITER
  7.  
  8. **CALL PARAMETERS :-    (TRAP #1 TO ACTIVATE !)
  9.  
  10. ** D0=START CYLINDER
  11. ** D1=NUMBER OF CYLINDERS
  12. ** D2=MFM BUFFER (RESERVE $5000 BYTES !)
  13. ** A0=DESTINATION ADDRESS
  14.  
  15. ** INITIAL PARAMETERS :-
  16. ** MFMD=INITAL MFM BUFFER ADDRESS
  17. ** SYSBASE=LOADER BASE ADDRESS/STACK ADDRESS (SUGGESTED =<$1000)
  18. ** INITIALLOAD=ADDRESS TO LOAD INITIAL DATA + INITIAL JUMP
  19. ** STARTCYL/NUMCYL=START CYLINDER+NUMBER TO LOAD
  20. ** ISR=INITAL STATUS REGISTER
  21.  
  22.     section    loader2,code_c
  23.     opt    c-,d-
  24.  
  25. time=2148                a bit more than 3 milliseconds !
  26. mfmd=$7b000                Set buffer to $7b000
  27. sysbase=$400                $400 for stack+loader code (+TRAP1)
  28. initialload=$1000            Initial load+jump address
  29. startcyl=62                Start cylinder
  30. numcyl=8                Number of cylinders to load
  31. ISR=$2000                Supervisor + Enable all Ints.
  32.  
  33.  
  34. intreqr    EQU    $01E
  35. dskpt    EQU    $020
  36. dsklen    EQU    $024
  37. dsksync    EQU    $07E
  38. dmacon    EQU    $096
  39. intena    EQU    $09A
  40. intreq    EQU    $09C
  41. adkcon    EQU    $09E
  42. bplcon0    EQU    $100
  43. color    EQU    $180
  44.  
  45. **BOOT STUFF !!
  46.     dc.b    "DOS",0
  47.     ds.l    1
  48.     dc.l    $370
  49.  
  50. bootstart
  51.     lea    bootem(pc),a0
  52.     move.l    a0,$20.w
  53. bootem    move.w    #ISR,sr
  54.     bsr    loadreg
  55.     move.w    #$7fff,d0
  56.     move.w    d0,intena-$24(a5)
  57.     move.w    d0,dmacon-$24(a5)     no ints. or dma
  58.     move.w    d0,adkcon-$24(a5)    clear disk control !!
  59.     move.b    #$08,$e00(a3)        one-shot mode
  60.     move.w    #$9500,adkcon-$24(a5)    set prefs for disk
  61.     move.w    #$4489,dsksync-$24(a5)    standard sync
  62.     bset    #1,(a3)            set LED
  63.  
  64.     bsr    activatedrive
  65. .loop1    btst    #4,(a3)            track 0 ?
  66.     beq.s    setupdma
  67.     bsr    headsout        step heads out
  68.     bra.s    .loop1
  69. setupdma
  70.     moveq    #0,d1
  71.     move.w    d1,bplcon0-$24(a5)    no colors !!
  72.     lea    $140-$24(a5),a0
  73.     moveq    #16,d0
  74. .nosprt    move.l    d1,(a0)+
  75.     dbra    d0,.nosprt        clear sprites & color0 !!
  76.  
  77.     lea    mainloader(pc),a0
  78.     lea    sysbase,a1        loader base address
  79.     move.l    a1,$84.w
  80.     move.l    a1,a7
  81.     moveq    #(loaderend-mainloader)/4,d0
  82. .copydown
  83.     move.l    (a0)+,(a1)+        copy
  84.     dbra    d0,.copydown
  85.  
  86.     lea    startloader(pc),a0
  87.     move.l    a1,a2
  88.     moveq    #mainloader-startloader-1,d0 not to overwrite !
  89. .copyinit
  90.     move.b    (a0)+,(a1)+
  91.     dbra    d0,.copyinit
  92.     jmp    (a2)
  93.  
  94. startloader
  95.     lea    initialload,a0        load address
  96.     moveq    #startcyl,d0        start cylinder
  97.     moveq    #numcyl,d1        number of cylinders
  98.     move.l    #mfmd,d2        mfm address !
  99.     trap    #1            load tracks
  100.     jmp    (a0)            into progy !!
  101.  
  102. mainloader
  103.     movem.l    d0-d7/a0-a6,-(sp)    save all regs.
  104.     bsr    loadreg            load my regs.
  105.     movem.l    d2/a0,mfm(a4)        mfm maddress + dest address !
  106.  
  107.     bsr.s    activatedrive
  108.  
  109.     bsr    step            step heads to cylinder
  110.     bsr.s    readendecode        read cylinders + decode 'em
  111.     bsr.s    drivesoff
  112.  
  113.     movem.l    (sp)+,d0-d7/a0-a6
  114.     rte                return
  115.  
  116. drivesoff
  117.     move.b    #$f9,(a6)
  118.     move.b    #$f1,(a6)
  119.     rts
  120.  
  121. activatedrive
  122.     move.b    #$79,(a6)        all drive bits on high !!
  123.     move.b    #$71,(a6)
  124.     bsr    waitdrive
  125.     rts
  126.  
  127. readendecode
  128.     bset    #2,(a6)        read head 0 !
  129.     bsr.s    loaderror
  130. .error1    bsr.s    checkerror
  131.     bsr.s    read
  132.     bsr.s    decode
  133.     bne.s    .error1
  134.     bclr    #2,(a6)        read head 1 !
  135.     bsr.s    loaderror
  136. .error2    bsr.s    checkerror
  137.     bsr.s    read
  138.     bsr.s    decode
  139.     bne.s    .error2
  140.  
  141.     cmp.w    #79,(a4)    are we on track 79 !!
  142.     beq.s    exitl        yes then exit !!
  143.     addq.w    #1,(a4)        add 1 to track !
  144.  
  145.     bsr    headin
  146.     subq.w    #1,d0        tracks to read
  147.     bne.s    readendecode
  148. exitl    rts
  149. loaderror
  150.     move.w    #11,error(a4)
  151.     rts
  152.  
  153. checkerror
  154.     subq.w    #1,error(a4)
  155.     bne.s    exitl
  156.     bsr.s    drivesoff
  157.     moveq    #-1,d0
  158. .loop    move.w    d0,$180-$24(a5)
  159.     dbra    d0,.loop
  160. .hold    bra.s    .hold
  161.  
  162. read
  163.     move.w    #$8210,dmacon-$24(a5)    enable disk dma
  164.     move.l    mfm(a4),dskpt-$24(a5)    destination
  165.     move.w    #$4000,d6
  166.     move.w    d6,(a5)
  167.     move.w    #$9900,d3
  168.     move.w    d3,(a5)
  169.     move.w    d3,(a5)            read 7000 mfm words
  170.     moveq    #$2,d7
  171.     move.w    d7,intreq-$24(a5) clear DISK BLOCK DONE interupt request
  172. .waitblock
  173.     move.w    intreqr-$24(a5),d1
  174.     and.w    d7,d1
  175.     beq.s    .waitblock        test for DISK BLOCK DONE,wait till read
  176.     move.w    d6,(a5)            no more dma
  177.     move.w    #$10,dmacon-$24(a5)
  178.     rts
  179.  
  180. decode
  181.     move.l    #$55555555,d3    mask off in d3
  182.     move.l    mfm(a4),a0
  183.     lea    $4f00(a0),a1    store track table address !
  184.     move.l    a1,-(sp)
  185.     move.w    #$4489,d6    standard sync !!
  186.     moveq    #10,d7        11 sectors
  187.  
  188. .loop0    cmp.w    (a0)+,d6
  189.     bne.s    .loop0
  190.     cmp.w    (a0),d6        2nd sync ?
  191.     beq.s    .loop0        found branch
  192. .loop2    move.l    a0,a2
  193.     movem.l    (a0),d1-d2    info part
  194.     and.l    d3,D1
  195.     and.l    d3,d2
  196.     add.l    d1,d1
  197.     or.l    d2,d1        decode block info
  198.     lsr.w    #8,d1
  199.     move.w    d1,(a1)+    save sector
  200.     lea    44(a0),a0    block checksum
  201.     move.l    (a0)+,d5    block checksum in d5
  202.  
  203.     moveq    #9,d1        byte count
  204. .bc    move.l    (a2)+,d4
  205.     eor.l    d4,d5        eor with checksum
  206.     dbra    d1,.bc        calculate header checksum
  207.     and.l    d3,d5        mask clock bits
  208.     bne.s    loadreg        return on error
  209.  
  210.     addq.l    #4,a0        align for data checksum
  211.     move.l    (a0)+,(a1)+    data checksum !!
  212.     move.l    a0,(a1)+    and address of data
  213.     lea    1024(a0),a0    next sector
  214.     dbra    d7,.loop0    for all tracks
  215.  
  216.     move.l    current(a4),a1    address of decoded data
  217.     move.l    (sp)+,a0    restore track table !
  218.     moveq    #$A,d7        11 sectors
  219. .loop3    move.w    (a0)+,d1    sector
  220.     moveq    #9,d2
  221.     lsl.w    d2,d1        multiply by 512
  222.     lea    0(a1,d1.w),a3    multiply by 1 sector and save address
  223.  
  224.     movem.l    (a0)+,d2/a2    checksum + start of data
  225.     lea    512(a2),a5    next set of datas
  226.     moveq    #512/4-1,d4
  227. .dcode    move.l    (a2)+,d5    data
  228.     move.l    (a5)+,d6    data
  229.     eor.l    d6,d2
  230.     eor.l    d5,d2        fix data checksum !!
  231.  
  232.     and.l    d3,d5
  233.     and.l    d3,d6
  234.     add.l    d5,d5
  235.     or.l    d6,d5
  236.     move.l    d5,(a3)+    save data
  237.     dbra    d4,.dcode    continue
  238.     and.l    d3,d2        mask checksum
  239.     bne.s    loadreg        if sum is ok then branch
  240. .sumok    dbra    d7,.loop3
  241.     add.l    #512*11,current(a4)
  242.     bsr.s    loadreg
  243.     moveq    #0,d7        clear error
  244.     rts
  245.  
  246. loadreg
  247.     lea    $bfe001.l,a3
  248.     lea    data(pc),a4
  249.     lea    -$f01(a3),a6
  250.     lea    $dff024.l,a5
  251.     rts
  252.  
  253.  
  254. step    move.w    (a4),d2        current track
  255.     exg    d0,d1        swap !
  256.     move.w    d1,(a4)        start track
  257.     sub.w    d2,d1        subtract to get number of tracks to skip
  258.     bmi.s    headout        step heads out if difference is negative
  259.     beq.s    .ret1        0, then there already
  260. .loop0    bsr.s    headin        step heads in
  261.     subq.w    #1,d1
  262.     bne.s    .loop0
  263. .ret1    rts
  264.  
  265. headout
  266. .loop0    bsr.s    headsout
  267.     addq.w    #1,d1        for loop
  268.     bne.s    .loop0
  269.     rts
  270.  
  271. waitdrive
  272. .loop0    btst    #5,(a3)
  273.     bne.s    .loop0        drive ready ?, no wait
  274.     rts
  275.  
  276. headin
  277.     bclr    #1,(a6)
  278.     bra.s    stepit
  279. headsout
  280.     bset    #1,(a6)
  281. stepit
  282.     moveq    #0,d6
  283.     bclr    d6,(a6)
  284.     bset    d6,(a6)
  285.     move.b    #$7f,$d00(a3)
  286.     move.b    #time&$ff,$400(a3)
  287.     move.b    #time>>8,$500(a3)    set timer lo/hi & start timer
  288. .busy    btst    d6,$d00(a3)        wait for timer interupt
  289.     beq.s    .busy            busy then back !
  290.     rts
  291.  
  292.     rsreset
  293. track    rs.w    1
  294. mfm    rs.l    1
  295. current    rs.l    1
  296. error    rs.w    1
  297.  
  298. data    ds.w    1
  299. loaderend
  300.     end
  301.